/*
 * @Author: Y先森
 * @Date: 2023-04-11 16:00:35
 * @LastEditors: y && 250048395@qq.com
 * @LastEditTime: 2023-05-06 10:36:51
 * @FilePath: \y-website\src\store\modules\search.js
 */
export default {
    namespaced: true,
    state: () => ({
        historys: []
    }),
    mutations: {
        /**
         * 添加历史记录
         */
        addHistory(state, newHistory) {
            const isFindIndex = state.historys.findIndex(item=>{
                item === newHistory
            })
            if( isFindIndex != -1 ) {
                state.historys.splice(isFindIndex,1)
            } 
            state.historys.unshift(newHistory)
        },
        /**
         * 删除指定数据
         */
        deleteHistory(state, index) {
            state.historys.splice(index, 1)
        },
        /**
         * 删除所有历史记录
         */
        deleteAllHistory(state) {
            state.historys = []
        }
    }
}